const path = require('path')
const { merge }= require('webpack-merge')
const common = require('./webpack.common')
const OptimizeCssAssetsWebpackPlugin = require('optimize-css-assets-webpack-plugin')
const TerserWebpackPlugin = require('terser-webpack-plugin')
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const devConfig = {
  mode: 'production',
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
        { from: 'src/assets', to: 'assets' },
        {
          from: path.resolve(__dirname, './public/favicon.ico'),
          to: path.resolve(__dirname, './dist/assets/')
        }
      ]
    }),
    new HardSourceWebpackPlugin()
  ],
  optimization: {
    minimizer: [
      new OptimizeCssAssetsWebpackPlugin({
        assetNameRegExp: /\.css$/g,
        cssProcessor: require('cssnano'),
        cssProcessorOptions: {
          safe: true,
          discardComments: { removeAll: true }
        },
        canPrint: true
      }),
      new TerserWebpackPlugin({
        cache: true,
        parallel: true
      })
    ]
  }
}

module.exports = merge(common, devConfig)